package com.hmkj.core.po.commo;

import com.hmkj.common.baseMapper.GenericPo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;


/**
 * 交易品种表实体信息<br>
 *
 * @author eproo
 * @date   2017-11-07 04:23:42
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(description = "交易品种表")
@Table(name = "biz_commo")
public class Commo extends GenericPo<Integer> {

    public static final String TABLE_NAME = "biz_commo";


    /**品种名称**/
    @ApiModelProperty(value = "品种名称")
    private String name;
    /**品种代码**/
    @ApiModelProperty(value = "品种代码")
    private String code;
    /**品种图标**/
    @ApiModelProperty(value = "品种图标")
    private String icon;
    /**1,外盘:T1;2,内盘:T2;**/
    @ApiModelProperty(value = "1,外盘:T1;2,内盘:T2;")
    private Integer type;
    @Transient
    private String typeFormatter ;
    /**1,启用:T1;2,停用:T2;**/
    @ApiModelProperty(value = "1,启用:T1;2,停用:T2;")
    private Integer status;
    @Transient
    private String statusFormatter ;
    /**序号**/
    @ApiModelProperty(value = "序号")
    private Integer sortNo;
    /**品种描述**/
    @ApiModelProperty(value = "品种描述")
    private String decription;
    public String getTypeFormatter() {
        if(null == typeFormatter || "".equals(typeFormatter)){
            return TYPE.getValue(getType());
        }
        return this.typeFormatter;
    }
    public void setTypeFormatter(String typeFormatter) {
        this.typeFormatter=typeFormatter;
    }
    /**1,外盘:T1<br>2,内盘:T2<br>**/
    public enum TYPE {

        /**1,外盘:T1**/
        T1("外盘",1),

        /**2,内盘:T2**/
        T2("内盘",2);

        public final int code;
        public final String value;
        private static Map<Integer, String> map = new HashMap<Integer, String>();

        private TYPE(String value, int code) {
            this.code = code;
            this.value = value;
        }

        public static String getValue(Integer code) {
            if (null == code) {
                return null;
            }
            for (TYPE status : TYPE.values()) {
                if (status.code == code) {
                    return status.value;
                }
            }
            return null;
        }

        public static Integer getCode(String value) {
            if (null == value  || "".equals(value)) {
                return null;
            }
            for (TYPE status : TYPE.values()) {
                if (status.value.equals(value)) {
                    return status.code;
                }
            }
            return null;
        }

        public static  Map<Integer, String> getEnumMap() {
            if(map.size() == 0){
                for (TYPE status : TYPE.values()) {
                    map.put(status.code,status.value);
                }
            }
            return map;
        }
    }

    public String getStatusFormatter() {
        if(null == statusFormatter || "".equals(statusFormatter)){
            return STATUS.getValue(getStatus());
        }
        return this.statusFormatter;
    }
    public void setStatusFormatter(String statusFormatter) {
        this.statusFormatter=statusFormatter;
    }
    /**1,启用:T1<br>2,停用:T2<br>**/
    public enum STATUS {

        /**1,启用:T1**/
        T1("启用",1),

        /**2,停用:T2**/
        T2("停用",2);

        public final int code;
        public final String value;
        private static Map<Integer, String> map = new HashMap<Integer, String>();

        private STATUS(String value, int code) {
            this.code = code;
            this.value = value;
        }

        public static String getValue(Integer code) {
            if (null == code) {
                return null;
            }
            for (STATUS status : STATUS.values()) {
                if (status.code == code) {
                    return status.value;
                }
            }
            return null;
        }

        public static Integer getCode(String value) {
            if (null == value  || "".equals(value)) {
                return null;
            }
            for (STATUS status : STATUS.values()) {
                if (status.value.equals(value)) {
                    return status.code;
                }
            }
            return null;
        }

        public static  Map<Integer, String> getEnumMap() {
            if(map.size() == 0){
                for (STATUS status : STATUS.values()) {
                    map.put(status.code,status.value);
                }
            }
            return map;
        }
    }


    public Commo(){}

    public Commo(Consumer<Commo> consumer){
        consumer.accept(this);
    }
}